<template>
  <div class="articleList">
    <el-row class="search-container">
      <el-col :span="12">
        &nbsp;
        <!-- <el-menu default-active="1" class="el-menu-demo" mode="horizontal">
          <el-menu-item index="1">影响力排序</el-menu-item>
          <el-menu-item index="2">时间排序</el-menu-item>
        </el-menu> -->
      </el-col>
      <el-col :span="12" style="text-align:right">
        <span>关键词:</span>
        <el-input class="search-in" v-model="keyword"></el-input>
        <el-button type="primary" class="search-btn" @click="handleSearch">搜索</el-button>
      </el-col>
    </el-row>
    <div class="tips-container">
      <span>搜索关键词:{{keyword}} </span>
      <span class="count">共搜索到{{count}}条结果 </span>
    </div>
    <div v-if="belongGroup === 'keyfigures'||belongGroup === 'focusgroup'">
      <el-tabs v-model="activeName" @tab-click="tabHandleClick" style="margin-left:20px;">
        <el-tab-pane label="推特" name="twitter"></el-tab-pane>
        <el-tab-pane label="脸书" name="facebook"></el-tab-pane>
        <el-tab-pane label="领英" name="linkedin"></el-tab-pane>
        <el-tab-pane label="微博" name="weibo"></el-tab-pane>
      </el-tabs>
      <template v-for="(item,index) in articleList">
        <article-info :key="index" :info="item" :type="activeName"></article-info>
      </template>
    </div>
    <div class="article-container" v-else>
      <template v-for=" (item,index) in articleList">
        <article-info :key="index" :info="item"></article-info>
      </template>
    </div>
    <el-pagination style="margin-top:16px;" background layout="prev,pager, next,total" :current-page="page" :page-size="page_size" @current-change="handlerChangePage" @size-change="handlerChangeSize" :total="count">
    </el-pagination>
  </div>
</template>
<script>
import { getArticleList, getArticleListCount } from '@/api/archives'
const ArticleInfo = () => import('./article-info.vue')
export default {
  name: 'articleList',
  data() {
    return {
      // 发帖列表
      articleList: [],
      // 热词
      heatwords: [],
      // 关键词(敏感词)
      keywords: [],
      // 关键字
      keyword: '',
      // 当前页
      page: 1,
      // 总条数
      count: 0,
      // 每页条数
      page_size: 10,
      loading: true,
      activeName: 'twitter'
    }
  },
  props: {
    rowkey: String,
    objectUri: String,
    belongGroup: String
  },
  components: {
    ArticleInfo
  },
  mounted() {
    this.$nextTick(() => {
      this.getArticleList()
    })
  },
  methods: {
    // 搜索
    handleSearch() {
      this.page = 1
      this.getArticleList()
    },
    // 切换TAB
    tabHandleClick(tab) {
      this.getArticleList()
    },
    // 获取发帖数量
    async getArticleListCount() {
      let param = {
        rowkey: this.rowkey,
        objectUri: this.objectUri,
        keyword: this.keyword,
        tabType: this.activeName
      }
      getArticleListCount(param).then(response => {
        this.count = response.data
      })
    },
    // 获取发帖列表
    async getArticleList() {
      let param = {
        rowkey: this.rowkey,
        objectUri: this.objectUri,
        keyword: this.keyword,
        curpage: this.page,
        persize: this.page_size,
        tabType: this.activeName
      }
      getArticleList(param).then(response => {
        this.articleList = response.data.postList
        this.articleList.forEach(item => {
          if (item.personIconUrl) {
            item.iconUrl = item.personIconUrl
          }
        })
        this.keywords = response.data.keywords ? response.data.keywords : []
        this.heatwords = response.data.heatwords ? response.data.heatwords : []
        this.$root.Bus.$emit('setHeatwords', this.heatwords)
        this.$root.Bus.$emit('setKeywords', this.keywords)
        this.getArticleListCount()
      })
    },
    // 当前页改变时会触发
    handlerChangePage(val) {
      this.page = val
      this.getArticleList()
    },
    // 每页条数改变时会触发
    handlerChangeSize(val) {
      this.page_size = val
      this.getArticleList()
    }
  }
}
</script>
<style lang="scss" scoped>
.articleList {
  background: #fff;
  padding: 10px;
  .search-container {
    padding: 0px 0px 10px;
    .el-menu--horizontal {
      border-bottom: none;
      .el-menu-item {
        line-height: 32px;
        height: 32px;
      }
    }
    .search-btn {
      padding: 8px 15px;
    }
  }
  .tips-container {
    background: #f0f0f0;
    padding: 10px 10px;
    .count {
      float: right;
    }
  }
  .article-container {
    background: #f0f0f0;
    .article-item {
      margin: 5px 0;
      background: #fff;
      .user-container {
        padding: 0 10px;
        display: flex;
        align-items: center;
        .user-icon {
          height: 36px;
          width: 36px;
          border-radius: 36px;
        }
        .user-label {
          margin-left: 10px;
          line-height: 28px;
          h4 {
            display: inline-block;
            padding: 0 5px;
          }
          .el-button {
            padding: 4px 10px;
          }
        }
      }
      .content {
        padding: 5px 10px;
      }
      .quantitative-statistics {
        padding: 5px 10px;
        .thumbsUp-count {
          margin-right: 15px;
        }
        .score-box {
          float: right;
          .score {
            color: red;
          }
        }
      }
    }
  }
}
</style>
<style lang="scss">
.search-in {
  width: 50% !important;
  .el-input__inner {
    height: 32px;
    line-height: 32px;
  }
}
</style>
